﻿using Sabloane_de_proiectare.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;

namespace Sabloane_de_proiectare.Factory
{
    class RailFactory
    {
        private List<Type> cycleOrder;
        private int cycleListIndex;
        public RailFactory() { 
            cycleOrder = new List<Type>();
            cycleListIndex  = 0;
            cycleOrder.Add( typeof(Canvas));
            cycleOrder.Add( typeof(HorizontalRail) );
            cycleOrder.Add( typeof(VerticalRail) );
            cycleOrder.Add( typeof(BottomLeftTurnRail) );
            cycleOrder.Add( typeof(BottomRightTurnRail) );
            cycleOrder.Add( typeof(TopLeftTurnRail));
            cycleOrder.Add( typeof(TopRightTurnRail));
            cycleOrder.Add( typeof(CrossRail) );
        }
        public int getChildrenType() {
            return cycleListIndex;
        }
        public Canvas createNextItem( Type currentItem) {
            cycleListIndex = cycleOrder.IndexOf(currentItem);
            if (cycleListIndex == cycleOrder.Count - 1)
            {
                cycleListIndex = 0;
                return new Canvas();
            }
            else
            {
                cycleListIndex++;
            }
            Object returnedObj = new Object();
            returnedObj = Activator.CreateInstance(cycleOrder.ElementAt(cycleListIndex));
            return (Canvas)returnedObj;
        }
    }
}
